public class OrderItem {
    private String itemId;
    private String name;
    private Integer count;
    private double price;
    private double amount;

    private static final ItemRepository itemRepository = new ItemRepositoryTestImpl();

    public OrderItem(String itemId, String name, Integer count, double price, double amount) {
        this.itemId = itemId;
        this.name = name;
        this.count = count;
        this.price = price;
        this.amount = amount;
    }


    public static OrderItem from(String itemStr) {
        String[] split = itemStr.split(" x ", 2);

        System.out.print(split);

        String id = split[0];
        int count = Integer.parseInt(split[1]);

        Item productItem = itemRepository.findAll().stream()
                .filter(item -> item.getId().equals(id)).findAny().orElse(null);

        if (productItem == null) {
            return null;
        }
        return new OrderItem(productItem.getId(), productItem.getName(), count, productItem.getPrice(), productItem.getPrice() * count);
    }

    public double getAmount() {
        return amount;
    }

    public String getName() {
        return name;
    }

    public Integer getCount() {
        return count;
    }

    public double getPrice() {
        return price;
    }

    public String getItemId() {
        return itemId;
    }
}
